package we.libQ 
{
	import flash.display.BitmapData;
	import flash.geom.Matrix;
	import flash.geom.Point;
	import flash.utils.getTimer;
	/**
	 * ...
	 * @author worldedit
	 */
	public class BlitUtils 
	{
		
		public function BlitUtils() 
		{
			
		}
		
		public static function getKeyColoredBitmap(b:BitmapData,c:uint):BitmapData 
		{	
			var ret:BitmapData = new BitmapData(b.width, b.height);
			ret.copyPixels(b, b.rect, new Point(0, 0));
			var w:int = ret.width;
			while (w--)
			{
				var h:int = ret.height;
				while (h--)
				{
					if (ret.getPixel32(w, h) == c)
					ret.setPixel32(w, h, 0x00000000);
				}
			}
			return ret;
		}
		
		public static function swapColors(b:BitmapData,c1:uint,c2:int):BitmapData 
		{	
			var ret:BitmapData = new BitmapData(b.width, b.height);
			ret.copyPixels(b, b.rect, new Point(0, 0));
			var w:int = ret.width;
			while (w--)
			{
				var h:int = ret.height;
				while (h--)
				{
					if (ret.getPixel32(w, h) == c1)
					ret.setPixel32(w, h, c2);
				}
			}
			return ret;
		}
		
		public static function toString(b:BitmapData):String
		{
			return 'width: ' + b.width + '\nheight: ' + b.height + '\nnumPixels: ' + b.width * b.height;
		}
		
		public static function bake(b:BitmapData):BitmapData
		{
			var d:int = b.width > b.height?b.width:b.height;
			d *= 1.415;
			var ret:BitmapData = new BitmapData(d * 16, d, true, 0x00000000);
			var m:Matrix = new Matrix();
			for (var i:int = 0; i < 16; i++)
			{
				m.identity();
				m.translate( -b.width / 2, -b.height / 2);
				m.rotate(3.1415926 * 0.125 *  i);
				m.translate(d * i + b.width / 2, d / 2);
				ret.draw(b, m);
			}
			return ret;
		}
		
	}

}